#include <iostream>
using namespace std;
void test_cin_error();
void test_getline();

int main_getline()
{
    test_getline();
    // test_cin_error();
    return 0;
}

void test_cin_error()
{
    // cin.rdstate()和下面这几个值相"&"就可以知道各个错误位的设置了
    cout << ios:: failbit << endl;
    cout << ios:: eofbit << endl;
    cout << ios:: badbit << endl; 
    cout << ios:: goodbit << endl;
}

void test_getline()
{
    char names[5];
    char deserts[5];
    char result;
    cout << "Please input your name:" << endl;
    //当输入的长度大于设定的长度则会导致cin函数错误，同时会抛弃换行符，导致后面的cin不会执行
    cin.getline(names, 5);
    //判断是否是
    cout << "cin good ? " << cin.good() << endl;
    cout << "Please input your favourite food: " << endl;
    cin >> result;
    cout << "the result is=[" << (int)result << "]\n";
    //当输入的长度大于设定的长度时不会报错，同时空格，enter都会存到缓存区中
    //所以直接使用cin >> someValue; cout << someValue; 就会打印出来相应的值
    //https://blog.csdn.net/a3192048/article/details/80303547
    cin.get(deserts, 5);
    cout << names << "'s favourite food is:" << deserts << endl;
    /*
    Please input your name:
    mikekekKkk
    cin good ? 0
    Please input your favourite food: 
    the result is=[0]
    mike's favourite food is:
    */

}
